package com.neuedu.corejava.ch9;

public class StringClass {

	public static void main(String[] args) {

		String  s=new String("aba");
		//java 的字符串对象是不可以修改的，每次修改字符串都会分配新的内存空间
		//String类的修改性能很低
		s=new String("sfsdfds");
		s=new String("sffsaafe");
		s=new String("sfsdfds1");
		
		//带缓冲的字符串类---StringBuffer线程安全；StringBuilder线程不安全
		//Stringbuffer与StringBuilder功能基本一样
		//面试题;简述String，Stringbuffer，Stringbuilder的异同
		StringBuffer buffer=new StringBuffer();
		//StringBuilder buffer=new StringBuilder();
		buffer.append(false);
		buffer.append("hello");
		buffer.insert(5, "ABCDEF");
		
		int cap=buffer.capacity();//字符串缓冲的容量
		int len=buffer.length();//数据长度
		
		System.out.println(cap+","+len);
		System.out.println(buffer.toString());
		System.out.println("=================");
		
		buffer.insert(0, "A");
		 cap=buffer.capacity();//字符串缓冲的容量
		 len=buffer.length();//数据长度
		 System.out.println(cap+","+len);
		 System.out.println(buffer.toString());
		 System.out.println("=================");
		 
		 //buffer.deleteCharAt(0);
		 //buffer.delete(0, 5);
		 buffer.trimToSize();//释放没有使用的空间容量
		 
		 cap=buffer.capacity();//字符串缓冲的容量
		 len=buffer.length();//数据长度
		 System.out.println(cap+","+len);
		 System.out.println(buffer.toString());
		 System.out.println("=================");
		 
		// buffer.replace(0, buffer.length(), "A");
		 buffer=buffer.reverse();//反转
		 System.out.println(buffer.toString());
		 
		
	}

}
